<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")	{
				
				$txtcountry = mysql_real_escape_string($_REQUEST['txtcountry']);
				$txtisocode2 = mysql_real_escape_string($_REQUEST['txtisocode2']);
				$txtisocode3 = mysql_real_escape_string($_REQUEST['txtisocode3']);

				$insert="INSERT INTO `tblcountry` ( `varcountryname` , `char_iso-code2` , `char_iso-code3`) 
				VALUES ('$txtcountry', '$txtisocode2', '$txtisocode3')";
				$sql=$obj_db->insert($insert);
				// get Id of inserted record
				$screen_id = mysql_insert_id($obj_db->CONN);			
		header("location:country.php?msg=add");
		die();
}	
		

// UPDATE the record
$txtcountry1 = "";
$txtisocode21 = "";
$txtisocode31 = "";
$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblcountry where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$txtcountry1 = $row['varcountryname'];	   
		   		$txtisocode21 = $row['char_iso-code2'];
				$txtisocode31 = $row['char_iso-code3'];
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				$txtcountry = mysql_real_escape_string($_REQUEST['txtcountry']);
				$txtisocode2 = mysql_real_escape_string($_REQUEST['txtisocode2']);
				$txtisocode3 = mysql_real_escape_string($_REQUEST['txtisocode3']);
				
			
				$sql_upd ="UPDATE tblcountry SET
						`varcountryname` = '$txtcountry',
						`char_iso-code2` = '$txtisocode2',						 
						`char_iso-code3` = '$txtisocode3'
						where intid ='$screen_id'";

				$result = $obj_db->edit($sql_upd);
				$action=1;						
		header("location:country.php?msg=edit");
		die();
		
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tblcountry` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:country.php?msg=del");
		die();
	}
}


?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/country.js"></script>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addcountry' || trim($_REQUEST['script'])=='editcountry')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="country">
	
      <table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addcountry'){echo "Add New Country...";}
	if($_REQUEST['script']=='editcountry'){echo "Edit Country...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="7%">&nbsp;</td>
          <td width="25%" align="right" class="sltimg">*Country Name</td>
          <td width="3%">:</td>
          <td width="61%" align="left"><label>
            <input name="txtcountry" type="text" id="txtcountry" value="<?php echo stripslashes($txtcountry1);?>" />
          </label></td>
          <td width="4%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*ISO Code -2</td>
          <td>:</td>
          <td align="left"><input name="txtisocode2" type="text" id="txtisocode2" value="<?php echo stripslashes($txtisocode21);?>" maxlength="2" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*ISO Code -3</td>
          <td>:</td>
          <td align="left"><input name="txtisocode3" type="text" id="txtisocode3" value="<?php echo stripslashes($txtisocode31);?>" maxlength="3" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table></form>
    <?php
	}
}
else
{
?>
<br />
<br />
		<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="4" align="left"><strong>Country List... </strong>&nbsp;&nbsp;<a href="country.php?script=addcountry" class="aa"></a></td>
            <td align="center"><a href="country.php?script=addcountry" class="aa">[NEW]</a></td>
          </tr>
          <tr>
             <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="2" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
			   </td>
				</form>
          </tr>
          <tr class="tblbg3">
            <td align="center"><strong><?php 
		if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
			{
		?>
		<a  class="ab1" href="country.php?sort=alphadesc">Country&nbsp;<img src="../images/down.gif" border="0" /></a>
		<?php 
			}
			else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
			{
		?><a class="ab1" href="country.php?sort=alphaasc">Country&nbsp;<img src="../images/up.gif" border="0" /></a>
		<?php }
			else
			{
			 ?>
			 <a class="ab1" href="country.php?sort=alphadesc">Country</a>
			 <?php
		 }?></strong></td>
            <td align="center"><strong>ISO -2</strong></td>
            <td align="center"><strong>ISO -3</strong></td>
            <td align="center"><strong>Edit</strong></td>
            <td align="center"><strong>Delete</strong></td>
          </tr>
          <?php  
	  
	  	/**************************************
				PAGING CODE START
		**************************************/
		if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}
		$tablename="tblcountry";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
		 if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
		{ 
   		$sql="select * from tblcountry order by `varcountryname` asc Limit ".($page_no*$row_per_page).",".$row_per_page;
		}
		else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
		{
		$sql="select * from tblcountry order by `varcountryname` desc Limit ".($page_no*$row_per_page).",".$row_per_page;
		}
		else
		{
		$sql="select * from tblcountry Limit ".($page_no*$row_per_page).",".$row_per_page;
		}
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><?php echo $result[$i]['varcountryname'];?></td>
            <td align="center"><?php echo stripslashes($result[$i]['char_iso-code2']);?></td>
            <td align="center"><?php echo stripslashes($result[$i]['char_iso-code3']);?></td>
            <td align="center"><a Title="Click here to Edit" href="country.php?script=editcountry&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="country.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php }}?>
          <tr>
            <td colspan="6" align="center"><?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page); ?></td>
          </tr>
        </table>
		<?php }?>
   	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>


